#ifndef _BATTLESESSION_H_
#define _BATTLESESSION_H_



#include "GameEnemy.h"
#include "GamePlayer.h"
#include "GameNpc.h"


class DexCompare
{
public:

	bool operator ()( GameCreature* a , GameCreature* b ) const        
	{
		return a->mFightData.Base.Quick > b->mFightData.Base.Quick;
	}

};

// battle data
// attacker or defender 
// action type
// attacker side
// defender side
// attacker num
// defender num
// attacker type * attacker num
// attacker index * attacker num
// defender type * defender num
// defender index * defender num
// result type * defender num , 
// result * defender num, fint32


// struct resutlMsg 
// {
// 	fbyte level;
// 	fbyte petLevel;
// 
// 	fint32 exp;
// 	fint32 petExp;
// 
// 	fint32 nextExp;
// 	fint32 petNextExp;
// 
// 
// };


class BattleSession
{
public:
	
	friend class BattleManager;
	
	
	DexCompare				mCompare;
	
	BattleSession();
	~BattleSession();
	
	fvoid					InitPVP( GamePlayer* player1 , GamePlayer* player2 );
	fvoid					InitPVE( GamePlayer* player , fint32 num , fint32 petNum , GameNpc* npc = F_NULL );
	GameEnemyEntity*		GetEnemy( fint32 index );
	GameEnemyEntity*		GetEnemyPet( fint32 index );
	
	fvoid					AddCommand( GamePlayer* player , const CreatureFightCommand& command , const CreatureFightCommand& commandPet );
	fvoid					Fight();
	
	fvoid					NextTurn();
	fvoid					BattleOver();
	
	fvoid					Release();
	
	//fbool					Update( freal32 delay );
	
	fint16					Down( GameCreature* c1 , GameCreature* c2 );
	fvoid					DoResult( GameCreatureVector& v );
	fint16					ComputerFight( GameEnemyEntity* enemy );
	fvoid					ComputerRandCommand( GameEnemyEntity* enemy );
	
	fvoid					CheckBattle();
	fvoid					CloseBattle();
	
	fvoid					SendMsgToAll();
	
protected:
	
	GameCreatureList		mList;
	GameCreatureVector		mVectorAttack;
	
	SABattleSessionType		mType;
	fint32					mTurn;
	
	GameNpc*				mNpc;

	fint32					mNumberCommand;
	fbool					mWaitCommand[ MAX_BATTLE_PLAYER ];
	fint32					mNumberCommandPVP;
	fbool					mWaitCommandPVP[ MAX_BATTLE_PLAYER ];

	fint32					mNumberPlayer;
	GamePlayer*				mPlayer[ MAX_BATTLE_PLAYER ];
	
	fint32					mNumberPlayerPVP;
	GamePlayer*				mPlayerPVP[ MAX_BATTLE_PLAYER ];

	GameCreature			mAttacker[ MAX_BATTLE_ENEMY ];
	
	fint32					mNumEnemy;
	GameEnemyEntity			mEnemyEntity[ MAX_BATTLE_ENEMY ];
	
	fint32					mNumEnemyPet;
	GameEnemyEntity			mEnemyEntityPet[ MAX_BATTLE_ENEMY ];
	
};



#endif

